/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \class ETFHistManager
  \brief a singleton manager class to manage all kinds of histograms.
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2024-06-18
  \date 2024-06-18 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2024-06-18   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <TH1.h>
#include "ETFHistManager.h"
#include "ETFMsg.h"

ETFHistManager *ETFHistManager::kInstance = nullptr;

ETFHistManager::ETFHistManager(){}

ETFHistManager *ETFHistManager::Instance(){
  if(!kInstance) kInstance = new ETFHistManager();
  return kInstance;
} // end ctor

ETFHistManager::~ETFHistManager(){}

TH1 *ETFHistManager::GetHist(const string &hname){
  if(!fMap.count(hname)){
    ETFMsg::Warn("ETFHistManager", "GetHist: no record for %s", hname.data());
    return nullptr;
  } // end if
  return fMap.at(hname);
} // end member function GetHist

void ETFHistManager::AddHist(const string &hname, TH1 *ph){
  if(fMap.count(hname)){
    ETFMsg::Warn("ETFHistManager", "AddHist: a record for %s exists", hname.data());
    return;
  } // end if
  fMap[hname] = ph;
} // end member function AddHist
